<template>
  <a-card :bordered='false'>
    <search :config='searchConfig' @search='search' @getHeight='getHeight' />
    <div class='page_table'>
      <vxe-grid
        ref='xGrid'
        :border='true'
        :resizable='true'
        :showOverflow='true'
        size='mini'
        :loading='loading'
        :height='pageHeight-seachHeight-94'
        :align='left'
        :columns='columns'
        :data='dataSource'
        :toolbar-config="tableToolbar"
       :checkbox-config="checkboxConfig"
        v-bind='vexConfig'
        @checkbox-change='selectChangeEvent'
        @checkbox-all="selectChangeEvent"
      >
        <template #toolbar_buttons>
          <div class='table-operator'>
            <a-button @click="handleAdd" type="primary">新增</a-button>
            <a-button type="primary" @click="startorstop('009')">启用</a-button>
            <a-button type="primary" @click="startorstop('003')">禁用</a-button>
            <a-button tabindex="primary" @click="batchDel">删除</a-button>
            <a-button type="primary" @click="downExportXls('sign_config')">导出</a-button>
<!--            <a-button type="primary">日志</a-button>-->
          </div>
        </template>
        <template  #action='{ row,rowIndex }'>
          <a v-has="'getGoodsAdress:update'" @click='handleEdit(row)'>编辑</a>
          <a-divider type='vertical' />
          <a v-has="'business:log'" href='javascript:' @click='handleBusiness("考勤规则",row)'>日志</a>

        </template>
        <template #detail="{row}">
          <a @click="handleDetail(row)">{{ row.signConfigCode }}</a>
        </template>
        <template #receivingAddressCode='{ row,rowIndex }'>
          <a @click="handleDetail(row)">{{ row.receivingAddressCode }}</a>
        </template>
        <template #status="{ row,rowIndex }">
          <a-switch :checked="row.status" size="small" @change="handleStatus(row,$event)"/>
        </template>
        <template #pager>
            <vxe-pager
              :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
              :currentPage.sync='ipagination.current'
              :page-size.sync='ipagination.pageSize'
              :total='ipagination.total'
              :pageSizes='ipagination.pageSizeOptions'
              @page-change='handlePageChange'>
            </vxe-pager>
        </template>
      </vxe-grid>
    </div>
    <!-- 弹出框 -->
    <sfaSignConfig-modal ref="modalForm" @ok="modalFormOk"></sfaSignConfig-modal>
    <business-log ref="businessLog"></business-log>
  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import SfaSignConfigModal from './modules/SfaSignConfigModal'
  import {PageListMixin} from '@/mixins/PageListMixin'
  import {getAction , httpAction} from '@/api/manage'
  import ARow from 'ant-design-vue/es/grid/Row'
  import ARangePicker from 'ant-design-vue/es/date-picker/RangePicker'
  export default {
    name: "SignConfigList",
    mixins: [PageListMixin],
    components: {
      ARangePicker,
      ARow,
      SfaSignConfigModal
    },
    data() {
      return {
        description: '考勤规则管理页面',
        // 表头
        showImg:false,
        imgSrc:"",
        searchConfig: [
          {
            type: 'input',
            name: 'signConfigCode',
            placeholder: '规则编码'
          },
          {
            type: 'input',
            name: 'signConfigName',
            placeholder: '规则名称'
          },
          // {
          //   type: 'j-select',
          //   name: 'signConfigType',
          //   dictCode: 'sign_config_type',
          //   placeholder: '规则类型'
          // },
        ],
        columns: [
          {
            width:60,
            type:'checkbox',
          },
          {
            title: '规则编码',
            minWidth:80,
            field: 'signConfigCode',
            slots: { default: 'detail' }
          },
          {
            title: '规则名称',
            minWidth:80,
            field: 'signConfigName'
          },
          // {
          //   title: '规则类型',
          //   minWidth:80,
          //   field: 'signConfigTypeStr'
          // },

          // {
          //   title: '签到开始时间',
          //   minWidth:120,
          //   field: 'signInStart'
          // },
          // {
          //   title: '签到结束时间',
          //   minWidth:120,
          //   field: 'signInEnd'
          // },
          // {
          //   title: '签退开始时间',
          //   minWidth:120,
          //   field: 'signOutStart'
          // },
          // {
          //   title: '签退结束时间',
          //   minWidth:120,
          //   field: 'signOutEnd'
          // },
          {
            title: '区域',
            minWidth:80,
            field: 'signOrgName'
          },
          {
            title: '创建人',
            minWidth:80,
            field: 'createName'
          },
          {
            title: '创建时间',
            minWidth:80,
            field: 'createTime'
          },
          {
            title: '更新人',
            minWidth:80,
            field: 'updateName'
          },
          {
            title: '更新时间',
            minWidth:80,
            field: 'updateTime'
          },
          {
            title: '状态',
            minWidth:80,
            field: 'status',
            slots: { default: 'status' }
          },

          {
            title: '操作',
            field: 'action',
            width: 120,
            slots: { default: 'action' }
          }
        ],
        isorter: {
          permflag: 'sign_config_page_impl'
        },
        url: {
          list: window._CONFIG['domianSfaURL'] + "/signConfig/findPageList",
          delete: window._CONFIG['domianSfaURL'] + "/signConfig/deleteById",
          detail: window._CONFIG['domianSfaURL'] + "/signConfig/getDetailById",
          deleteBatch: window._CONFIG['domianSfaURL'] + "/signConfig/deleteBatch",
          startOrStopUrl: window._CONFIG['domianSfaURL'] + "/signConfig/startOrStop"
        }
      }
    },

    methods: {
      // 行内切换状态
      async handleStatus(row, status, method = 'get') {
        let that = this
        this.loading = true
        if(status){
          status = 1
        }else {
          status = 0
        }
        let params = { ids: row.id,status:status}
        let res = await httpAction(that.url.startOrStopUrl, params, method)
        if (res.success) {
          that.$message.success(res.message)
          that.onClearSelected()
        } else {
          that.$message.warning(res.message)
        }
        that.loadData()
      },
      startorstop: function (status) {
        if (!this.url.startOrStopUrl) {
          this.$message.error("请设置url启用停用!")
          return;
        }
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');
          return;
        }else{
          var ids = "";
          for (let i = 0; i < this.selectedRowKeys.length; i++) {
            ids += this.selectedRowKeys[i] + ",";
          }
        }
        let param = {...this.queryParam}
        if(status === '009'){
          param['status'] = 1
        }else{
          param['status'] = 0
        }
        if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
          param['ids'] = this.selectedRowKeys.join(",")
        }else {
          param['ids'] = this.selectedRowKeys[0]
        }
        // if (this.selectedRowKeys.length != 1) {
        //   this.$message.warning('请选择一条记录！');
        //   return;
        // } else {
        // var id = this.selectedRowKeys;
        var that = this;
        that.loading = true;
        getAction(this.url.startOrStopUrl, param ).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.loadData();
          } else {
            that.$message.warning(res.message);
          }
          that.loading = false;
        });
      }
    }
  }
</script>

<style scoped>
  @import '~@assets/less/common.less';
</style>